package com.iterator.controller.wechat.wy.collect;

import com.iterator.bean.web.pojo.BaseRespVo;
import com.iterator.bean.wechat.wy.collect.AddordeleteBO;
import com.iterator.bean.wechat.wy.collect.AddordeletevVO;
import com.iterator.bean.wechat.wy.collect.CollectVO;
import com.iterator.service.wechat.wy.collect.WxCollectService;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: Silence_W
 * @date: 2021-01-12 21:02
 **/
@RestController
@RequestMapping("wx/collect")
public class CollectController {

    @Autowired
    WxCollectService wxCollectService;

    //收藏夹的数据显示
    @RequestMapping("list")
    public BaseRespVo list(Integer type,Integer page,Integer size){

        Subject subject = SecurityUtils.getSubject();
        String username = (String) subject.getPrincipal();
        Integer id = wxCollectService.queryIdByUsername(username);
        CollectVO collectVO = wxCollectService.queryCollect(id,type,page,size);

        return BaseRespVo.ok(collectVO);
    }

    @RequestMapping("addordelete")
    public BaseRespVo addordelete(@RequestBody AddordeleteBO addordeleteBO){
        Subject subject = SecurityUtils.getSubject();
        String username = (String) subject.getPrincipal();
        Integer id = wxCollectService.queryIdByUsername(username);
        AddordeletevVO addordeletevVO = wxCollectService.deleteCollect(id,addordeleteBO.getType(),addordeleteBO.getValueId());

        return BaseRespVo.ok(addordeletevVO);
    }
}
